//
// Created by Administrator on 2019/12/10.
//
#include "CFunLearn.h"

void testMacro()
{
#ifdef DEBUG
    printf("debug is defined");
    printf("MIN(2, 3) = %d", MIN(2, 3));
#endif
    printf("MKSTR = %s", MKSTR(hellomacro));
    printf("CONCAT = %d", CONCAT(1, 45));
    printf("Current line = %d", __LINE__);
    printf("Current file = %s", __FILE__);
}

double mypow(double d, int p){
    double r = 1;
    for(int i=0;i<p;i++){
        r *= d;
    }
    return r;
}

time_t getSeconds(unsigned long *p)
{
    return time(0);
}

void getRandom()
{
    srand((unsigned)time(0));
    printf("rand() = %d", rand());
}

void swap(int* a, int* b)
{
    int *temp = a;
    a = b;
    b = temp;
}

void timeOpr()
{
    time_t now = time(0);
    char *pnow = ctime(&now);
    printf("local time: %s", pnow);

    struct tm *gmtm = gmtime(&now);
    printf("UTC time: %s", asctime(gmtm));


    struct tm *lcl = localtime(&now);
    printf("year: %d\t", lcl->tm_year + 1900);
    printf("month: %d\t", lcl->tm_mon + 1);
    printf("today: %d\t", lcl->tm_mday);

    char tmp[20];
    strftime(tmp, sizeof(tmp),"%Y-%m-%d %H:%M:%S",lcl);
    printf("%s\n", tmp);
}
